找传奇、传世资源到传世资源站!

纸牌游戏21点 源码下载

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

一个不错的学习例子,希望可以帮到正在研究做游戏的朋友们,注意哦,是C#开发的.

private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } private void 新游戏ToolStripMenuItem_Click(object sender, EventArgs e) //新游戏,将游戏中所有的数据清空或归位; { index = 0; count = 0; maskedTextBox1.ReadOnly = false; a = 0; b = 0; c = 0; d = 0; f = 0; g = 0; h = 0; o = 0; ii = 1; ss = 0; aa = 0; diannao = 0; q1 = 0; qq = 0; duoyu = 0; xiazhu = 0; zongshu = 0; pictureBox1.Hide(); pictureBox2.Hide(); pictureBox3.Hide(); pictureBox4.Hide(); pictureBox5.Hide(); pictureBox6.Hide(); pictureBox7.Hide(); pictureBox8.Hide(); pictureBox15.Hide(); pictureBox9.Hide(); pictureBox10.Hide(); pictureBox11.Hide(); pictureBox12.Hide(); pictureBox13.Hide(); pictureBox14.Hide(); button4.Enabled = false; button8.Enabled = false; button7.Enabled = false; button6.Enabled = false; button9.Enabled = true; button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button9.Enabled = true; button5.Enabled = true; maskedTextBox1.Enabled = true; label13.Text = ""; maskedTextBox1.Text = ""; label7.Text = "0"; label4.Text = "1000"; label11.Text = ""; label14.Text = ""; } private void button4_Click(object sender, EventArgs e) //开局,与新游戏唯一的不同就是label4没有清空!! { index = 0; count = 0; label18.Text = ""; label6.Text = "0"; label14.Text = "0"; a = 0; b = 0; c = 0; d = 0; f = 0; g = 0; h = 0; o = 0; ii = 1; ss = 0; aa = 0; diannao = 0; qq = 0; xiazhu = 0; zongshu = 0; duoyu = 0; pictureBox1.Hide(); pictureBox2.Hide(); pictureBox3.Hide(); pictureBox4.Hide(); pictureBox5.Hide(); pictureBox6.Hide(); pictureBox7.Hide(); pictureBox8.Hide(); pictureBox15.Hide(); pictureBox9.Hide(); pictureBox10.Hide(); pictureBox11.Hide(); pictureBox12.Hide(); pictureBox13.Hide(); pictureBox14.Hide(); button4.Enabled = false; button8.Enabled = false; button7.Enabled = false; button6.Enabled = false; button9.Enabled = true; button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button9.Enabled = true; button5.Enabled = true; maskedTextBox1.Enabled = true; label13.Text = ""; maskedTextBox1.Text = ""; label7.Text = "0"; label11.Text = ""; q1 = 0; } private void Form1_Load(object sender, EventArgs e) //游戏执行时因为没有用到pictureBox,所以将所有的pictureBox隐藏; { pictureBox1.Hide(); pictureBox2.Hide(); pictureBox3.Hide(); pictureBox4.Hide(); pictureBox13.Hide(); pictureBox5.Hide(); pictureBox6.Hide(); pictureBox7.Hide(); pictureBox8.Hide(); pictureBox14.Hide(); pictureBox15.Hide(); pictureBox9.Hide(); pictureBox10.Hide(); pictureBox11.Hide(); pictureBox12.Hide(); maskedTextBox1.ReadOnly = true; } double zijin = 0, zongjin, zongshu = 0, shiqu, diannao, xiazhu, duoyu; Random randon = new Random(); //随机数定义 int a, b, c, d, f, g, h, o, l, m, n, y, z, v; //为每一个pictureBox的牌面的点数的定义 int ss, aa, qq = 0, ii = 1, q1 = 0; double d1, d2, d3, d4, d5, d6, d7; //这个是电脑牌面数值的定义; double w1, w2, w3, w4, w5, w6, w7; //这个是玩家牌面的定义; private void 帮助框ToolStripMenuItem_Click(object sender, EventArgs e) //打开帮助面板,为新的窗体; { Form2 a = new Form2(); a.Show(); } public void an_Click(object sender, EventArgs e) //游戏正式开始时,要下注,这个为下注的Button的设定代码;(100、200、500) { string bot = ((Button)sender).Text; int lab7 = int.Parse(bot); q1 = q1 lab7; if (q1 >= Convert.ToInt32(label4.Text)) { q1 = Convert.ToInt32(label4.Text); button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; button5.Enabled = false; } label7.Text = q1.ToString(); button6.Enabled = true; button7.Enabled = false; button4.Enabled = false; if (duoyu == 1) xiazhu = 0; duoyu = 0; } public void jiapai_Click(object sender, EventArgs e) //Button6,发牌 { if (double.Parse(label4.Text) < double.Parse(label7.Text)) //如果玩家下注大于现有资金的最大值,便将现有资金全数作为下注金额; label7.Text = label4.Text; pictureBox1.Show();pictureBox2.Show(); //四个PictureBox,1、2是庄家的前面两张牌,8、9是玩家的前面两张牌; pictureBox8.Show();pictureBox9.Show(); switch (ii) //ii是作为进入玩家加牌的数值定义,因为玩家是一张一张牌来增加的。 { case 1: //ii的默认值为1; { pictureBox1.Image = Image.FromFile("tupian\\53.jpg"); //电脑台面上的第一张牌,为背面,无用 a = randon.Next(52);//随机选出第一张牌,为电脑台面上的第二张牌,因为是第一张随机选出的牌,所以不用判断是否与其它的牌重复 pictureBox2.Image = Image.FromFile("tupian\\" a.ToString() ".jpg"); //电脑台面上的第二张牌,同时也是作为基础牌面要计算数值的第一张牌; d1 = a % 13 1; //将所得的牌转换成1~13的数字 if (d1 > 10) //判断是否为11、12、13这三个数字,如果是,就将它转换为10; d1 = 10; b = randon.Next(52);//这里往下就是玩家的第一张牌,与之相应的是在文件夹中名字为0~51的图片; while (b == a) //当玩家的这个随机得到的牌与庄家得到的第一张随机的牌相同时,则重新生成一个随机数,让它与前面的牌的点数不一样; { b = randon.Next(52); } w1 = b % 13 1; //计算出随机得到的数所在的牌的点数 if (w1 > 10) //当得到的点数>10的时候,即11、12、13,将它们变成10(作为21点游戏的规则而设定的) w1 = 10; zongshu = w1; //zongshu是玩家所得的点数相加之和的定义 pictureBox8.Image = Image.FromFile("tupian\\" b.ToString() ".jpg"); //将玩家随机得到的第一张牌显示出来 c = randon.Next(52);//这里往下为玩家的第二张牌,一直往下相似的代码均为此效果; while (c == a || c == b) { c = randon.Next(52); } w2 = c % 13 1; if (w2 > 10) w2 = 10; zongshu = w2; pictureBox9.Image = Image.FromFile("tupian\\" c.ToString() ".jpg"); if (w1 == 1 && w2 != 1) //这里是判断BlackJack的地方,只有当玩家的开始得到的两张牌为一张A与一张大于等于10的牌时,玩家即为得到了BlackJack; { if (w1 w2 == 11) //BlackJack的胜利条件是一张A和一张10点的牌,所以相加为11; { //MessageBox.Show("恭喜你取得了BlackJack!!"); index = 0; count = 0; timer1.Enabled = true; yin = 30000; m1 = 30031; timer2.Enabled = true; button6.Enabled = false; //这里相应的按钮效果 button7.Enabled = false; button8.Enabled = false; button4.Enabled = true; zijin = 1.5 * double.Parse(label7.Text); //将下注金额与现有金额化为数值,并将下注金额的1.5倍加入原有的金额中 zongjin = double.Parse(label4.Text); zongjin = zijin; label4.Text = zongjin.ToString(); goto aaa; //因为得到了BlackJack,所以用Goto语句强行结束这个Switch语句 } else if (w1 w2 != 11) //这里自然是没能取得BlackJack的判断语句,由于这个语句的进入条件是w1为A,所以将w1看做11; zongshu = 10; aa = 1; } else if (w2 == 1 && w1 != 1) //与上面相反,这里是w2的条件为A时进入的判断,其余同上 { if (w2 w1 == 11) { //MessageBox.Show("恭喜你取得了BlackJack!!"); index = 0; count = 0; timer1.Enabled = true; yin = 30000; m1 = 30031; timer2.Enabled = true; button6.Enabled = false; button7.Enabled = false; button8.Enabled = false; button4.Enabled = true; zijin = 1.5 * double.Parse(label7.Text); zongjin = double.Parse(label4.Text); zongjin = zijin; label4.Text = zongjin.ToString(); goto aaa; } else if (w2 w1 != 11) zongshu = 10; aa = 1; } else if (w1 == 1 && w2 == 1) { zongshu = 12; aa = 1; } ii = 13; } break; case 13: { d = randon.Next(52); //这里是玩家取得第三张牌的地方 while (d == a || d == b || d == c) { d = randon.Next(52); } w3 = d % 13 1; if (w3 >= 10) w3 = 10; zongshu = w3; if (w3 == 1) { zongshu = 10; if (zongshu > 21) zongshu -= 10; } pictureBox10.Show(); pictureBox10.Image = Image.FromFile("tupian\\" d.ToString() ".jpg"); if (zongshu > 21) //判断玩家拿到三张牌后是否超过21点 { if (aa == 1) { zongshu -= 10; aa = 0; } if (zongshu > 21) { yin = 20000; m1 = 20035; timer2.Enabled = true; label18.Text = "输"; shiqu = double.Parse(label7.Text); label14.Text = shiqu.ToString(); zongjin = double.Parse(label4.Text); zongjin -= shiqu; label4.Text = zongjin.ToString(); qq = 1; goto asa; } } ii = 14; } break; case 14: { f = randon.Next(52); //这里是玩家取得四张牌的地方; while (f == a || f == b || f == c || f == d) { f = randon.Next(52); } w4 = f % 13 1; //这个是判断玩家取得4张牌后是否超过21点 if (w4 >= 10) w4 = 10; zongshu = w4; if (w4 == 1) { zongshu = 10; if (zongshu > 21) zongshu -= 10; } pictureBox11.Show(); pictureBox11.Image = Image.FromFile("tupian\\" f.ToString() ".jpg"); if (zongshu > 21) { if (aa == 1) { zongshu -= 10; aa = 0; } if (zongshu > 21) { yin = 20000; m1 = 20035; timer2.Enabled = true; label18.Text = "输"; shiqu = double.Parse(label7.Text); label14.Text = shiqu.ToString(); zongjin = double.Parse(label4.Text); zongjin -= shiqu; label4.Text = zongjin.ToString(); qq = 1; goto asa; } } ii = 15; } break; case 15: { g = randon.Next(52); //这里是玩家取得5张牌的地方; while (g == a || g == b || g == c || g == d || g == f) { g = randon.Next(52); } w5 = g % 13 1; //这个是判断玩家取得5张牌后是否超过21点 if (w5 >= 10) w5 = 10; zongshu = w5; if (w5 == 1) { zongshu = 10; if (zongshu > 21) zongshu -= 10; } pictureBox12.Show(); pictureBox12.Image = Image.FromFile("tupian\\" g.ToString() ".jpg"); if (zongshu > 21) { if (aa == 1) { zongshu -= 10; aa = 0; } if (zongshu > 21) { yin = 20000; m1 = 20035; timer2.Enabled = true; label18.Text = "输"; shiqu = double.Parse(label7.Text); label14.Text = shiqu.ToString(); zongjin = double.Parse(label4.Text); zongjin -= shiqu; label4.Text = zongjin.ToString(); qq = 1; goto asa; } } ii = 16; } break; case 16: { h = randon.Next(52); //这里是玩家取得6张牌的地方; while (h == a || h == b || c == h || h == d || h == f || h == g) { h = randon.Next(52); } w6 = h % 13 1; //这个是判断玩家取得6张牌后是否超过21点 if (w6 >= 10) w6 = 10; zongshu = w6; if (w6 == 1) { zongshu = 10; if (zongshu > 21) zongshu -= 10; } pictureBox13.Show(); pictureBox13.Image = Image.FromFile("tupian\\" h.ToString() ".jpg"); if (zongshu > 21) { if (aa == 1) { zongshu -= 10; aa = 0; } if (zongshu > 21) { yin = 20000; m1 = 20035; timer2.Enabled = true; label18.Text = "输"; shiqu = double.Parse(label7.Text); label14.Text = shiqu.ToString(); zongjin = double.Parse(label4.Text); zongjin -= shiqu; label4.Text = zongjin.ToString(); qq = 1; goto asa; } } ii = 17; } break; case 17: { o = randon.Next(52); //这里是玩家取得7张牌的地方 while (o == a || o == b || o == c || o == d || o == f || o == g || o == h) { o = randon.Next(52); } w7 = o % 13 1; //这个是判断玩家取得7张牌后是否超过21点 if (w7 >= 10) w7 = 10; zongshu = w7; if (w7 == 1) { zongshu = 10; if (zongshu > 21) zongshu -= 10; } pictureBox14.Show(); pictureBox14.Image = Image.FromFile("tupian\\" o.ToString() ".jpg"); if (zongshu > 21) { if (aa == 1) { zongshu -= 10; aa = 0; } if (zongshu > 21) { yin = 20000; m1 = 20035; timer2.Enabled = true; label18.Text = "输"; shiqu = double.Parse(label7.Text); label14.Text = shiqu.ToString(); zongjin = double.Parse(label4.Text); zongjin -= shiqu; label4.Text = zongjin.ToString(); qq = 1; goto asa; } } } break; } button6.Enabled = false; button7.Enabled = true; button8.Enabled = true; aaa: button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; button5.Enabled = false; button9.Enabled = false; maskedTextBox1 .Enabled = false; asa: if (qq == 1) { button4.Enabled = true; button7.Enabled = false; button8.Enabled = false; qq = 0; } if (label4.Text == "0") button4.Enabled = false; //当玩家的所有金额为0时,则将洗牌这个按钮隐去不能使用,这样就这能点击新游戏重新开始游戏了 }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复